home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / kant-generator-04-c / Kant ƒ / Shell ƒ / about.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  3.9 KB  |  164 lines  |  [TEXT/MMCC]

  1. #include "about.h"
  2. #include "prefs.h"
  3. #include "util.h"
  4.  
  5. /*-----------------------------------------------------------------------------------*/
  6. /* internal stuff for about.c                                                        */
  7.  
  8. void SetupTheAboutBox(WindowDataHandle theData);
  9. void InitializeTheAboutBox(WindowDataHandle theData);
  10. void OpenTheAboutBox(WindowDataHandle theData);
  11. void ResizeTheAboutBox(WindowDataHandle theData);
  12. void ShutdownTheAboutBox(WindowDataHandle theData);
  13. void DrawTheAboutBox(Boolean isColor);
  14. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  15. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter);
  16.  
  17. Boolean            gUseAlternate;
  18.  
  19. enum
  20. {
  21.     kAboutColorID=134
  22. };
  23.  
  24. short AboutBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  25. {
  26.     short            theDepth;
  27.     
  28.     switch (theMessage)    /* see graphics.h for list of messages*/
  29.     {
  30.         case kKeydown:                            /* close about box on keypress */
  31.         case kMousedown:                        /* or mouseclick */
  32.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  33.             return kSuccess;
  34.             break;
  35.         case kUpdate:
  36.             theDepth=misc&0x7fff;                /* pixel depth */
  37.             DrawTheAboutBox((theDepth>2));        /* we only care if it's color or not */
  38.             return kSuccess;
  39.             break;
  40.         case kInitialize:
  41.             InitializeTheAboutBox(theData);
  42.             return kFailure;
  43.         case kOpen:
  44.             OpenTheAboutBox(theData);
  45.             return kSuccess;
  46.             break;
  47.         case kStartup:
  48.             SetupTheAboutBox(theData);
  49.             return kSuccess;
  50.             break;
  51.         case kShutdown:
  52.             ShutdownTheAboutBox(theData);
  53.             return kSuccess;
  54.             break;
  55.     }
  56.     
  57.     return kFailure;        /* for all other messages, defer to default processing */
  58. }
  59.  
  60. void SetupTheAboutBox(WindowDataHandle theData)
  61. {
  62.     unsigned char    *theTitle="\pAbout";
  63.     
  64.     (**theData).windowType=noGrowDocProc;    /* plain vanilla window */
  65.     Mymemcpy((Ptr)((**theData).windowTitle), (Ptr)theTitle, theTitle[0]+1);
  66.     (**theData).hasCloseBox=TRUE;
  67.     (**theData).maxDepth=1;
  68.     gUseAlternate=FALSE;
  69. }
  70.  
  71. void InitializeTheAboutBox(WindowDataHandle theData)
  72. {
  73.     (**theData).windowWidth=170;
  74.     (**theData).windowHeight=216;
  75. }
  76.  
  77. void OpenTheAboutBox(WindowDataHandle theData)
  78. {
  79.     KeyMap            rawKeys;
  80.     unsigned short    theKeys[8];
  81.     
  82.     GetKeys(rawKeys);
  83.     Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
  84.     if (theKeys[3]&4)    /* option key down? */
  85.     {
  86.         if (!gUseAlternate)
  87.         {
  88.             gUseAlternate=TRUE;
  89.             (**theData).offscreenNeedsUpdate=TRUE;
  90.         }
  91.     }
  92.     else
  93.     {
  94.         if (gUseAlternate)
  95.         {
  96.             gUseAlternate=FALSE;
  97.             (**theData).offscreenNeedsUpdate=TRUE;
  98.         }
  99.     }
  100. }
  101.  
  102. void ShutdownTheAboutBox(WindowDataHandle theData)
  103. {
  104. }
  105.  
  106. void DrawTheAboutBox(Boolean isColor)
  107. {
  108.     short            row;
  109.     Handle            textHandle;
  110.     Str255            theLine;
  111.     unsigned long    pos;
  112.     unsigned long    theSize;
  113.     GrafPtr            curPort;
  114.     short            theCenter;
  115.     RGBColor        myGray={49152, 49152, 49152};
  116.     
  117.     GetPort(&curPort);
  118.     FillRect(&(curPort->portRect), &qd.black);
  119.     TextMode(srcXor);
  120.     
  121.     theCenter=(curPort->portRect.right-curPort->portRect.left)/2;
  122.     
  123.     TextFont(geneva);
  124.     TextSize(9);
  125.     row=16;
  126.     textHandle=GetResource('TEXT', gUseAlternate ? 129 : 128);
  127.     if (textHandle==0L)
  128.         return;
  129.     if (*textHandle==0L)
  130.         LoadResource(textHandle);
  131.     if (*textHandle==0L)
  132.         return;
  133.     pos=0L;
  134.     theSize=SizeResource(textHandle);
  135.     do
  136.     {
  137.         GetTheNextLine(textHandle, theSize, &pos, theLine);
  138.         DrawTheAboutString(theLine, &row, theCenter);
  139.     }
  140.     while (pos<theSize);
  141.     ReleaseResource(textHandle);
  142.     DrawTheAboutString(gMyName, &row, theCenter);
  143.     DrawTheAboutString(gMyOrg, &row, theCenter);
  144.     TextMode(srcCopy);
  145.     TextSize(12);
  146.     TextFont(0);
  147. }
  148.  
  149. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine)
  150. {
  151.     unsigned char    theChar;
  152.     
  153.     theLine[0]=0x00;
  154.     while ((*pos<theSize) && ((theChar=*((unsigned char*)(((long)(*textHandle))+((*pos)++))))!=0x0d))
  155.         theLine[++theLine[0]]=theChar;
  156. }
  157.  
  158. void DrawTheAboutString(Str255 theString, short *theRow, short theCenter)
  159. {
  160.     MoveTo(theCenter-StringWidth(theString)/2, *theRow);
  161.     DrawString(theString);
  162.     *theRow+=12;
  163. }
  164.